package com.me.demo.utility;

import com.me.demo.pojo.*;
import com.me.utils.ScreenDataUtility;

import java.util.*;

public class ThreadService {
    /**
     * http请求--服务器ip,port
     */
    final static String httpComm = "http://localhost:8080/";
    /**
     * 日期值班信息模型
     */
    static RiQiZhiBanXinXiModel riQiZhiBanXinXiModel = null;
    /**
     * 安全运营天数模型
     */
    static AnQuanYunYingTianShuModel anQuanYunYingTianShuModel = null;
    /**
     * 车站报警次数排名模型
     */
    static CheZhanBaoJingPaiMingModel cheZhanBaoJingPaiMingModel = null;
    static ArrayList<CheZhanBaoJingPaiMingModel.StationAlarm> stationAlarms = null;
    /**
     * 主变负荷模型
     */
    static ZhuBianFuHeModel zhuBianFuHeModel = null;
    static ZhuBianFuHeModel.PowerStationZBFH[] powerStations = null;
    /**
     * 专业报警矩阵
     */
    static ZhuanYeBaoJingJuZhenModel zhuanYeBaoJingJuZhenModel = null;
    /**
     * 能耗趋势图
     */
    static NengHaoQuShiModel nengHaoQuShiModel = null;
    /**
     * 列车行车指标
     */
    static LieCheXingCheZhiBiaoModel lieCheXingCheZhiBiaoModel = null;
    /**
     * 车站客流排名
     */
    static CheZhanKeLiuPaiMingModel cheZhanKeLiu = null;
    static ArrayList<CheZhanKeLiuPaiMingModel.StationPassengerFlow> passengerFlows = null;
    /**
     * 客流趋势图
     */
    static CheZhanKeLiuQuShiTuModel cheZhanKeLiuQuShiTuModel = null;
    /**
     * 列车报点信息
     */
    static LieCheBaoDian lieCheBaoDian = null;
    static ArrayList<LieCheBaoDian.ReportInfo> reportInfos = null;
    /**
     * 月进站客流趋势
     */
    static YueJinZhanKeLiuQuShiModel yueJinZhanKeLiuModel = null;
    static ArrayList<YueJinZhanKeLiuQuShiModel.YueJinZhanKeLiuQuShiModelItem> yueJinZhanQuShiItems = null;
    /**
     * 月行车趋势
     */
    static YueXingCheQuShiModel yueXingCheQuShiModel = null;
    static ArrayList<YueXingCheQuShiModel.YueXingCheQuShiModelItem> yueXingCheQuShiModelItems = null;
    /**
     * 月能耗趋势
     */
    static YueNengHaoQuShiModel yueNengHaoQuShiModel = null;
    static ArrayList<YueNengHaoQuShiModel.YueNengHaoQuShiModelItem> yueNengHaoQuShiModelItems = null;
    /**
     * 站年客流排名
     */
    static ZhanNianKeLiuPaiMingModel zhanNianKeLiuPaiMingModel = null;
    static ArrayList<ZhanNianKeLiuPaiMingModel.StationPassengerFlow> stationPassengerFlows = null;
    /**
     * 行车指标
     */
    static XingCheZhiBiaoModel xingCheZhiBiaoModel = null;
    /**
     * 能耗类型占比
     */
    static NengHaoLeiXingZhanBiModel nengHaoLeiXingZhanBiModel = null;

    static {
        riQiZhiBanXinXiModel = new RiQiZhiBanXinXiModel();
        anQuanYunYingTianShuModel = new AnQuanYunYingTianShuModel();
        //@----------------------start
        cheZhanBaoJingPaiMingModel = new CheZhanBaoJingPaiMingModel();
        stationAlarms = new ArrayList<CheZhanBaoJingPaiMingModel.StationAlarm>(6);
        for (int i = 0; i < 6; i++) {
            CheZhanBaoJingPaiMingModel.StationAlarm temp = cheZhanBaoJingPaiMingModel.new StationAlarm();
            stationAlarms.add(temp);
        }
        cheZhanBaoJingPaiMingModel.setStationAlarms(stationAlarms);
        //@----------------------end

        //@----------------------start
        zhuBianFuHeModel = new ZhuBianFuHeModel();
        powerStations = new ZhuBianFuHeModel.PowerStationZBFH[2];
        for (int i = 0; i < 2; i++) {
            ZhuBianFuHeModel.PowerStationZBFH temp = zhuBianFuHeModel.new PowerStationZBFH();
            powerStations[i] = (temp);
        }
        zhuBianFuHeModel.setPowerStations(powerStations);
        //@----------------------end

        zhuanYeBaoJingJuZhenModel = new ZhuanYeBaoJingJuZhenModel();
        nengHaoQuShiModel = new NengHaoQuShiModel();
        lieCheXingCheZhiBiaoModel = new LieCheXingCheZhiBiaoModel();

        //@----------------------start
        cheZhanKeLiu = new CheZhanKeLiuPaiMingModel();
        passengerFlows = new ArrayList<CheZhanKeLiuPaiMingModel.StationPassengerFlow>(6);
        for (int i = 0; i < 6; i++) {
            CheZhanKeLiuPaiMingModel.StationPassengerFlow temp = cheZhanKeLiu.new StationPassengerFlow();
            passengerFlows.add(temp);
        }
        cheZhanKeLiu.setPassengerFlows(passengerFlows);
        //@----------------------end

        cheZhanKeLiuQuShiTuModel = new CheZhanKeLiuQuShiTuModel();

        //@----------------------start
        lieCheBaoDian = new LieCheBaoDian();
        reportInfos = new ArrayList<LieCheBaoDian.ReportInfo>(6);
        for (int i = 0; i < 6; i++) {
            LieCheBaoDian.ReportInfo temp = lieCheBaoDian.new ReportInfo();
            reportInfos.add(temp);
        }
        lieCheBaoDian.setReportInfos(reportInfos);
        //@----------------------end

        //@----------------------start
        yueJinZhanKeLiuModel = new YueJinZhanKeLiuQuShiModel();
        yueJinZhanQuShiItems = new ArrayList<YueJinZhanKeLiuQuShiModel.YueJinZhanKeLiuQuShiModelItem>(12);
        for (int i = 0; i < 12; i++) {
            YueJinZhanKeLiuQuShiModel.YueJinZhanKeLiuQuShiModelItem temp = yueJinZhanKeLiuModel.new YueJinZhanKeLiuQuShiModelItem();
            yueJinZhanQuShiItems.add(temp);
        }
        yueJinZhanKeLiuModel.setYueJinZhanQuShiItems(yueJinZhanQuShiItems);
        //@----------------------end

        //@----------------------start
        yueXingCheQuShiModel = new YueXingCheQuShiModel();
        yueXingCheQuShiModelItems = new ArrayList<YueXingCheQuShiModel.YueXingCheQuShiModelItem>(12);
        for (int i = 0; i < 12; i++) {
            YueXingCheQuShiModel.YueXingCheQuShiModelItem temp = yueXingCheQuShiModel.new YueXingCheQuShiModelItem();
            yueXingCheQuShiModelItems.add(temp);
        }
        yueXingCheQuShiModel.setYueXingCheQuShiModelItems(yueXingCheQuShiModelItems);
        //@----------------------end

        //@----------------------start
        yueNengHaoQuShiModel = new YueNengHaoQuShiModel();
        yueNengHaoQuShiModelItems = new ArrayList<YueNengHaoQuShiModel.YueNengHaoQuShiModelItem>(12);
        for (int i = 0; i < 12; i++) {
            YueNengHaoQuShiModel.YueNengHaoQuShiModelItem temp = yueNengHaoQuShiModel.new YueNengHaoQuShiModelItem();
            yueNengHaoQuShiModelItems.add(temp);
        }
        yueNengHaoQuShiModel.setYueNengHaoQuShiModelItems(yueNengHaoQuShiModelItems);
        //@----------------------end

        //@----------------------start
        zhanNianKeLiuPaiMingModel = new ZhanNianKeLiuPaiMingModel();
        stationPassengerFlows = new ArrayList<ZhanNianKeLiuPaiMingModel.StationPassengerFlow>(6);
        for (int i = 0; i < 6; i++) {
            ZhanNianKeLiuPaiMingModel.StationPassengerFlow temp = zhanNianKeLiuPaiMingModel.new StationPassengerFlow();
            stationPassengerFlows.add(temp);
        }
        zhanNianKeLiuPaiMingModel.setPassengerFlows(stationPassengerFlows);
        //@----------------------end

        xingCheZhiBiaoModel = new XingCheZhiBiaoModel();
        nengHaoLeiXingZhanBiModel = new NengHaoLeiXingZhanBiModel();
    }

    /*
     * 定义所有的请求路径，存储所有的servlet请求
     * */
    private static String[] https = new String[]{
            ScreenDataUtility.getAnQuanYunYingTianShuData(),
            ScreenDataUtility.getCheZhanBaoJingPaiMingData(),
            ScreenDataUtility.getLieCheXingCheZhiBiaoData(),
            ScreenDataUtility.getNengHaoQuShiTuData(),
            ScreenDataUtility.getRiQiZhiBanXinXiData(),
            ScreenDataUtility.getZhuanYeBaoJingJuZhenData(),
            ScreenDataUtility.getZhuSuoFuHeData(),
            ScreenDataUtility.getCheZhanKeLiuPaiMingData(),
            ScreenDataUtility.getKeLiuQuShiTuData(),
            ScreenDataUtility.getLieCheShiShiBaoDianXinXiData(),
            ScreenDataUtility.getYueJinZhanKeLiuQuShiData(),
            ScreenDataUtility.getYueXingCheQuShiData(),
            ScreenDataUtility.getYueNengHaoQuShiData(),
            ScreenDataUtility.getZhanNianKeLiuPaiMingData(),
            ScreenDataUtility.getXingCheZhiBiaoData(),
            ScreenDataUtility.getNengHaoLeiXingZhanBiData()
    };

    /**
     * 后端程序启动
     */
    public static void start() {
        HttpURLConnectionUtility.httpURLConnectionPOST(httpComm + "start");
    }

    /**
     * 刷新数据
     *
     * @param timeInterval 2s刷新率
     */
    public static void requestHttpPostConnection(long timeInterval) {
        for (String http : https) {
            try {
                Thread.sleep(10);
                Runnable runnable = new Runnable() {
                    public void run() {
                        try {
                            while (true) {
                                //code for task to run
                                HttpURLConnectionUtility.httpURLConnectionPOST(httpComm + http);
                                //ends here
                                try {
                                    Thread.sleep(timeInterval);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };
                new Thread(runnable).start();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 提供   日期值班组件   数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static RiQiZhiBanXinXiModel runRiQiZhiBanXinXiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            String[] phones = ScreenDataUtility.nextPhones();
            String[] zby = ScreenDataUtility.nextBanYuans();
            riQiZhiBanXinXiModel.setInfoName0(ScreenDataUtility.nextBanZhang());
            riQiZhiBanXinXiModel.setInfoName1(zby[0]);
            riQiZhiBanXinXiModel.setInfoName2(zby[1]);
            riQiZhiBanXinXiModel.setInfoPhone0(phones[0]);
            riQiZhiBanXinXiModel.setInfoPhone1(phones[1]);
            riQiZhiBanXinXiModel.setInfoPhone2(phones[2]);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return riQiZhiBanXinXiModel;
    }

    /**
     * 提供   安全运营天数组件   数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static AnQuanYunYingTianShuModel runAnQuanYunYingTianShuDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            anQuanYunYingTianShuModel.setCompValue(ScreenDataUtility.nextDay());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return anQuanYunYingTianShuModel;
    }

    /**
     * 提供   车站报警次数排名组件   数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static CheZhanBaoJingPaiMingModel runCheZhanBaoJingPaiMingDataTask(long timeInterval) {
        //java的写法
        //public class A {
        //   public class B {
        //   }
        //};
        //A a = new A();
        //A.B ab = a.new B();
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            String[] stations = ScreenDataUtility.nextStations(6);
            Integer[] counts = ScreenDataUtility.nextInteger(6, 10);
            for (int i = 0; i < stationAlarms.size(); i++) {
                stationAlarms.get(i).setAlarmCount(counts[i]);
                stationAlarms.get(i).setStationName(stations[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cheZhanBaoJingPaiMingModel;
    }

    /**
     * 提供   主变负荷组件   数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static ZhuBianFuHeModel runZhuBianFuHeDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            String[] stations = ScreenDataUtility.nextStations(2);
            Integer[] counts = ScreenDataUtility.nextInteger(4, 100);
            ArrayList<String> ids = new ArrayList<String>(Arrays.asList("1#", "2#"));
            for (int i = 0; i < powerStations.length; i++) {
                powerStations[i].setIds(ids);
                powerStations[i].setPowers(new String[]{counts[i].toString(), counts[i + 2].toString()});
                powerStations[i].setStationName(stations[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return zhuBianFuHeModel;
    }

    /**
     * 提供   专业报警矩阵组件   数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static ZhuanYeBaoJingJuZhenModel runZhuanYeBaoJingJuZhenDataTask(long timeInterval) {
        try {
            //将int数组转换为Integer数组
            //int[] nums = {1,2,3};
            //先将int数组转换为数值流
            //IntStream stream = Arrays.stream(nums);
            //流中的元素全部装箱，转换为流 ---->int转为Integer
            //Stream<Integer> integerStream = stream.boxed();
            //将流转换为数组
            //Integer[] integers = integerStream.toArray(Integer[]::new);
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] temps = ScreenDataUtility.nextIntArray(30, -1000, 1000);
            zhuanYeBaoJingJuZhenModel.setAlarms(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(temps).boxed().toArray(Integer[]::new)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return zhuanYeBaoJingJuZhenModel;
    }

    /**
     * 提供  能耗趋势组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static NengHaoQuShiModel runNengHaoQuShiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            double[] electricityConsumptions = ScreenDataUtility.nextDouble(96, 5.0, 20.0);
            double[] energyConsumptionLastWeek = ScreenDataUtility.nextDouble(96, 1.0, 15.0);
            nengHaoQuShiModel.setElectricityConsumption(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(electricityConsumptions).boxed().toArray(Double[]::new)));
            nengHaoQuShiModel.setEnergyConsumptionLastWeek(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(energyConsumptionLastWeek).boxed().toArray(Double[]::new)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return nengHaoQuShiModel;
    }

    /**
     * 提供  列车行车指标组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static LieCheXingCheZhiBiaoModel runlieCheXingCheZhiBiaoDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] temps = ScreenDataUtility.nextIntArray(4, 1, 10);
            String time = ScreenDataUtility.generateTimeSpan();
            lieCheXingCheZhiBiaoModel.setCurrentOnlineTrain(String.valueOf(temps[0]));
            lieCheXingCheZhiBiaoModel.setCurrentOnlineDelayedTrain(String.valueOf(temps[1]));
            lieCheXingCheZhiBiaoModel.setDailyTotalDelayedTrains(String.valueOf(temps[2]));
            lieCheXingCheZhiBiaoModel.setNumberOfDoorFaultStates(String.valueOf(temps[3]));
            lieCheXingCheZhiBiaoModel.setLineTravelTime(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lieCheXingCheZhiBiaoModel;
    }

    static void SortCheZhanKeLiuPaiMing(ArrayList<CheZhanKeLiuPaiMingModel.StationPassengerFlow> list) {
        Collections.sort(list, new Comparator<CheZhanKeLiuPaiMingModel.StationPassengerFlow>() {
            @Override
            public int compare(CheZhanKeLiuPaiMingModel.StationPassengerFlow o1, CheZhanKeLiuPaiMingModel.StationPassengerFlow o2) {
                return (o1.getInStation() + o1.getOutStation()) - (o2.getInStation() + o2.getOutStation());
            }
        });
    }

    /**
     * 提供  车站客流排名组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static CheZhanKeLiuPaiMingModel runCheZHanKeLiuPaiMingDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            String[] stations = ScreenDataUtility.nextStations(6);
            int[] inStations = ScreenDataUtility.nextIntArray(6, 1, 50);
            int[] outStations = ScreenDataUtility.nextIntArray(6, 1, 50);
            for (int i = 0; i < passengerFlows.size(); i++) {
                passengerFlows.get(i).setInStation(inStations[i]);
                passengerFlows.get(i).setOutStation(outStations[i]);
                passengerFlows.get(i).setStationName(stations[i]);
            }
            SortCheZhanKeLiuPaiMing(passengerFlows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cheZhanKeLiu;
    }

    /**
     * 提供  车站客流趋势图组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static CheZhanKeLiuQuShiTuModel runCheZhanKeLiuQuShiTuDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] inStations = ScreenDataUtility.nextIntArray(67, 10000, 55000);
            int[] outStations = ScreenDataUtility.nextIntArray(67, 10000, 55500);
            int[] inStationsLast = ScreenDataUtility.nextIntArray(67, 5000, 50000);
            int[] outStationsLast = ScreenDataUtility.nextIntArray(67, 5000, 50000);
            cheZhanKeLiuQuShiTuModel.setInStationS(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(inStations).boxed().toArray(Integer[]::new)));
            cheZhanKeLiuQuShiTuModel.setOutStationS(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(outStations).boxed().toArray(Integer[]::new)));
            cheZhanKeLiuQuShiTuModel.setInStationsLastWeek(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(inStationsLast).boxed().toArray(Integer[]::new)));
            cheZhanKeLiuQuShiTuModel.setOutStationsLastWeek(ScreenDataUtility.converterFromNumericalArrToStringArr(Arrays.stream(outStationsLast).boxed().toArray(Integer[]::new)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cheZhanKeLiuQuShiTuModel;
    }

    /**
     * 提供  列车实时报点信息组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static LieCheBaoDian runLieCheShiShiBaoDianXinXiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            String[] nextStations = ScreenDataUtility.nextStations(6);
            String[] reportStations = ScreenDataUtility.nextStations(6);
            String[] trains = ScreenDataUtility.nextTrains(6);
            String[] planTimes = ScreenDataUtility.nextTimes(6);
            String[] reportTimes = ScreenDataUtility.nextTimes(6);
            for (int i = 0; i < 6; i++) {
                reportInfos.get(i).setNextStation(nextStations[i]);
                reportInfos.get(i).setPlanTime(planTimes[i]);
                reportInfos.get(i).setReportStation(reportStations[i]);
                reportInfos.get(i).setTrainNumber(trains[i]);
                reportInfos.get(i).setReportTime(reportTimes[i]);
                reportInfos.get(i).setState("正点");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lieCheBaoDian;
    }

    /**
     * 提供  月进站客流趋势组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static YueJinZhanKeLiuQuShiModel runYueJinZhanKeLiuQuShiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] inStations = ScreenDataUtility.nextIntArray(12, 0, 6000);
            int[] outStations = ScreenDataUtility.nextIntArray(12, 0, 6000);
            String[] months = ScreenDataUtility.getMonths();
            for (int i = 0; i < 12; i++) {
                yueJinZhanQuShiItems.get(i).setMonth(months[i]);
                yueJinZhanQuShiItems.get(i).setInStationPassengerFlow(String.valueOf(inStations[i]));
                yueJinZhanQuShiItems.get(i).setOutStationPassengerFlow(String.valueOf(outStations[i]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return yueJinZhanKeLiuModel;
    }

    /**
     * 提供  月行车趋势组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static YueXingCheQuShiModel runYueXingCheQuShiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] trians = ScreenDataUtility.nextIntArray(12, 4000, 6000);
            String[] months = ScreenDataUtility.getMonths();
            for (int i = 0; i < 12; i++) {
                yueXingCheQuShiModelItems.get(i).setMonth(months[i]);
                yueXingCheQuShiModelItems.get(i).setTrain(String.valueOf(trians[i]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return yueXingCheQuShiModel;
    }

    /**
     * 提供  月能耗趋势组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static YueNengHaoQuShiModel runYueNengHaoQuShiDataTask(long timeInterval) {
        try {
            //CommonData instance = (CommonData) SingleTonParent.getInstance(CommonData.class);
            int[] consumptions = ScreenDataUtility.nextIntArray(12, 4000, 6000);
            String[] months = ScreenDataUtility.getMonths();
            for (int i = 0; i < 12; i++) {
                yueNengHaoQuShiModelItems.get(i).setMonth(months[i]);
                yueNengHaoQuShiModelItems.get(i).setEnergyConsumption(String.valueOf(consumptions[i]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return yueNengHaoQuShiModel;
    }

    static void SortZhanNianKeLiuPaiMing(ArrayList<ZhanNianKeLiuPaiMingModel.StationPassengerFlow> list) {
        Collections.sort(list, new Comparator<ZhanNianKeLiuPaiMingModel.StationPassengerFlow>() {
            @Override
            public int compare(ZhanNianKeLiuPaiMingModel.StationPassengerFlow o1, ZhanNianKeLiuPaiMingModel.StationPassengerFlow o2) {
                return (o1.getInStation() + o1.getOutStation()) - (o2.getInStation() + o2.getOutStation());
            }
        });
    }

    /**
     * 提供  站年客流排名组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static ZhanNianKeLiuPaiMingModel runZhanNianKeLiuPaiMingDataTask(long timeInterval) {
        try {
            String[] stations = ScreenDataUtility.nextStations(6);
            int[] inStations = ScreenDataUtility.nextIntArray(6, 1, 4);
            int[] outStations = ScreenDataUtility.nextIntArray(6, 1, 5);
            for (int i = 0; i < stationPassengerFlows.size(); i++) {
                stationPassengerFlows.get(i).setInStation(inStations[i]);
                stationPassengerFlows.get(i).setOutStation(outStations[i]);
                stationPassengerFlows.get(i).setStationName(stations[i]);
            }
            SortZhanNianKeLiuPaiMing(stationPassengerFlows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return zhanNianKeLiuPaiMingModel;
    }

    /**
     * 提供  行车指标组件  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static XingCheZhiBiaoModel runXingCheZhiBiaoDataTask(long timeInterval) {
        try {
            xingCheZhiBiaoModel.setOperateTime(ScreenDataUtility.generateTimeSpan());
            xingCheZhiBiaoModel.setMinDepartureInterval(String.valueOf(ScreenDataUtility.nextIntArray(1, 2, 4)[0]));
            xingCheZhiBiaoModel.setMaxDepartureInterval(String.valueOf(ScreenDataUtility.nextIntArray(1, 2, 4)[0]));
            xingCheZhiBiaoModel.setOntimeRate(ScreenDataUtility.nextIntArray(1, 98, 100)[0] + "%");
            xingCheZhiBiaoModel.setDemandRate(ScreenDataUtility.nextIntArray(1, 98, 100)[0] + "%");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xingCheZhiBiaoModel;
    }

    /**
     * 提供  能耗类型占比  数据服务
     *
     * @param timeInterval=2000 2s刷新率
     * @return model 数据模型
     */
    public static NengHaoLeiXingZhanBiModel runNengHaoLeiXingZhanBiDataTask(long timeInterval) {
        try {
            String[] results = ScreenDataUtility.trisection(100);
            nengHaoLeiXingZhanBiModel.setTraction(results[0]);
            nengHaoLeiXingZhanBiModel.setDynamicLighting(results[1]);
            nengHaoLeiXingZhanBiModel.setLineLoss(results[2]);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return nengHaoLeiXingZhanBiModel;
    }
}


